<?php
$this->breadcrumbs = array(
	UserModule::t('Мои фирмы'),
);
?>

<h1><?php echo UserModule::t('Мои фирмы'); ?></h1>

<?php if(1 != Yii::app()->user->approved): ?>
<?php $this->renderPartial('/default/notapproved', array());?>
<?php else : ?>
	<p>
		<a href="<?php echo Yii::app()->createUrl('user/myfirms/create'); ?>" ><?php echo UserModule::t('Создать новую фирму');?></a> 
	</p>
    <div class="firms-list">
      <?php if (0 < count($firms)):?>
        <?php foreach($firms as $firm):?>
          <?php 
            $firm_lnk = Yii::app()->createUrl('/firm', array('id'=>$firm->id, 'slug'=> $firm->slug));
            $edit_lnk = Yii::app()->createUrl('user/myfirms/update', array('id'=>$firm->id, 'slug'=> $firm->slug));
            $delete_lnk = Yii::app()->createUrl('user/myfirms/delete', array('id'=>$firm->id));
    
        /*
            $service_lnk = Yii::app()->createUrl('/rubrics', array('st_id' => $firm->service_type));
            $rubric_lnk = Yii::app()->createUrl('/rubrics/single', array('st_id' => $firm->service_type, 'rid' => $firm->rubric_id));
            $category_lnk = Yii::app()->createUrl('/category', array('st_id' => $firm->service_type,'rid'=>$firm->rubric_id, 'cid'=>$firm->category_id));
            */
          ?>
          <div class="row-fluid">
            <div class="span9">
              <div class="well well-large firm-outer">
                <?php if ('' != $firm->logo):?>
                  <img src="<?php echo $this->getFirmImgSrc($firm->logo, 'firms_img_logo');?>" alt="" width="110" height="90" align="right" />
                <?php else: ?>
                  <img src="images/firms/110x90.gif" alt="" width="110" height="90" align="right" />
                <?php endif; ?>
                <?php if (0 < intval($firm->firmTmpl->has_detail_page)):?>
                  <h2><a href="<?php echo $firm_lnk; ?>"><?php echo GxHtml::encode($firm->title);?></a></h2>    
                <?php else: ?>
                  <h2><?php echo GxHtml::encode($firm->title);?></h2>
                <?php endif; ?>
                <article class="description">
                    <?php echo GxHtml::truncate(GxHtml::smart_encode(strip_tags($firm->description)), 300, '...', false);?>
                </article>
                <address>
                    <ul class="breadcrumb">
                        <li><?php echo GxHtml::encode($firm->region);?> <span class="divider">/</span></li>
                        <li><?php echo GxHtml::encode($firm->city);?> <span class="divider">/</span></li>
                        <li class="active"><?php echo GxHtml::encode($firm->address);?></li>
                    </ul>
                </address>
                <address>
                  <ul class="breadcrumb">
                      <li><?php echo GxHtml::encode($firm->firmTmpl->title);?> <span class="divider">/</span></li>
                      <li><?php echo $this->getServiceType($firm->service_type);?> <span class="divider">/</span></li>
                      <li><?php echo GxHtml::encode($firm->rubric);?> <span class="divider">/</span></li>
                      <li class="active"><?php echo GxHtml::encode($firm->category);?></li>
                  </ul>
                </address>							
                <div class="row-fluid">
                  <div class="span4"><?php echo Yii::t('app', 'Телефон:'); ?> <i class="text-info"><?php echo GxHtml::encode($firm->phone);?></i></div>
                  <div class="span4"><?php echo Yii::t('app', 'Допольнительный email:'); ?> <i class="text-info"><?php echo GxHtml::encode($firm->email);?></i></div>
                </div>
                <div class="row-fluid">
                  <div class="span3"><?php echo Yii::t('app', 'Дата создания:'); ?> <i class="text-info"><?php echo date('d/ m/ Y H:i', $firm->start_date);?></i></div>
                  <?php if (!in_array($firm->firmTmpl->id, $default_free_firm_tmpl_ids)): ?>
                    <?php 
                      $days = $firm->end_date - time();
                      $days = (0 < $days) ? round($days / 86400) : 0;
                    ?>
                    <div class="span2"><?php echo Yii::t('app', 'Осталось дней:'); ?> <i class="text-info"><?php echo $days;?></i></div>
                    <div class="span3"><?php echo Yii::t('app', 'Конечная дата:'); ?> <i class="text-info"><?php echo date('d/ m/ Y H:i', $firm->end_date);?></i></div>
                  <?php endif; ?>
                  <div class="span2"><?php echo Yii::t('app', 'Скрытая:'); ?> <i class="text-info">
                    <?php echo ($firm->hidden) ? UserModule::t('Да') : UserModule::t('Нет');?></i>
                  </div>
                  <div class="span2"><?php echo Yii::t('app', 'Утверждена:'); ?> <i class="text-info">
                    <?php echo ($firm->processed) ? UserModule::t('Yes') : UserModule::t('No');?></i>
                  </div>
                  <div class="span2"><?php echo Yii::t('app', 'Активирована:'); ?> <i class="text-info">
                    <?php echo ($firm->active) ? UserModule::t('Yes') : UserModule::t('No');?></i>
                  </div>
                </div>	
                <div class="row-fluid">								
                  <div class="span4">
                    <a href="<?echo $edit_lnk;?>">
                      <i class="text-info"><?php echo Yii::t('app', 'Редактировать'); ?></i>
                    </a>
                  </div>	
                  <div class="span4">
                    <a href="<?echo $delete_lnk;?>" onclick="return confirm('<?php echo Yii::t('app', 'Действительно хотите удалить эту запись?'); ?>');">
                      <i class="text-info"><?php echo Yii::t('app', 'Удалить'); ?></i>
                    </a>
                  </div>
                </div>
              </div>
            </div>
          </div>  
        <?php endforeach; ?>
      <?php else: ?>
          <p><?php echo Yii::t('app', 'Нет фирм'); ?></p>
      <?php endif; ?>
    </div>
	
	<?php /*$this->widget('zii.widgets.CListView', array(
		'dataProvider'=>$dataProvider,
		'itemView'=>'_view',
	)); */
	?>
<?php endif; ?>
